import { FormComponentProps } from "antd/lib/form/Form";
import { Moment } from "moment";
import { Dispatch } from "redux";
import { Reducers } from "../../../../../App";
import { IResBody } from "../../../../../common/config/http";
import {
  formHide_editAct,
  formSubmit_editAct,
  getTableDatasourceAct
} from "../../store/actions";
import {
  IReducerState_Form,
  IReducerState_TableFilter
} from "../../store/reducer";
import { IAreaSelect } from "../../interfaces";

// 修改时的表单
export interface IForm {
  id: number;
  areaId: number;
  loginIp: string;
  loginPwd: string;
  dialUpAccount: string;
  dialUpPwd: string;
  note: string;
}

interface IPropsState {
  formInfo: IReducerState_Form;
  filter: IReducerState_TableFilter;
  select_area: Array<IAreaSelect>;
}

interface IPropsDispatch {
  hide: (formInfo: IReducerState_Form) => void;
  submit: (formInfo:IReducerState_Form,data: any, callback: (res: IResBody) => void) => void;
  getTableDatasource: (filter: IReducerState_TableFilter) => void;
}

interface IExtra extends FormComponentProps {}

export type TProps = IPropsState & IPropsDispatch & IExtra;

export const mapStateToProps = (state: Reducers): IPropsState => {
  const reducer = state.manageVpsReducer;
  return {
    formInfo: reducer.form_info,
    filter: reducer.table_filter,
    select_area: reducer.select_area
  };
};

export const mapDispatchToProps = (dispatch: Dispatch): IPropsDispatch => ({
  submit(formInfo:IReducerState_Form,data: any, callback: (res: IResBody) => void) {
    const action: any = formSubmit_editAct(formInfo,data, callback);
    dispatch(action);
  },
  hide(formInfo: IReducerState_Form) {
    const action = formHide_editAct(formInfo);
    dispatch(action);
  },
  getTableDatasource(filter: IReducerState_TableFilter) {
    const action: any = getTableDatasourceAct(filter);
    dispatch(action);
  }
});
